/**
 * @Author:Geln Yang
 * @Created:2008-7-30
 * $ Revision: 1.0 $
 * $ Author: Geln Yang $
 * $ Date: 2008-7-30 $
 */
package org.geln.web.webwork.interceptor;

import java.util.Locale;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;

/**
 * @Author:Geln Yang
 * @Created:2008-7-30
 */
public class LocalizedInterceptor implements Interceptor {
	private static final Log log = LogFactory.getLog(LocalizedInterceptor.class);

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		Locale locale = ServletActionContext.getRequest().getLocale();
		if (log.isDebugEnabled()) {
			log.debug("default locale:" + ActionContext.getContext().getLocale());
			log.debug("user request locale:" + locale);
		}
		if (locale != null) {
			ActionContext.getContext().setLocale(locale);
		}
		return invocation.invoke();
	}

}
